home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 August / DPPCPRO0805.ISO / Assets / Interface / Main.dxr / Flash Components_1_Centre pane.swf / scripts / __Packages / TextPage.as < prev   
Encoding:
Text File  |  2005-05-20  |  7.2 KB  |  201 lines

  1. class TextPage extends mx.core.UIObject
  2. {
  3.    var __title;
  4.    var __body;
  5.    var dispatchEvent;
  6.    static var symbolName = "TextPage";
  7.    static var symbolOwner = TextPage;
  8.    var className = "TextPage";
  9.    static var version = "0.0.0.1";
  10.    static var __maxPageHeight = 376;
  11.    static var __pageBorder = 5;
  12.    static var __vSpacing = 5;
  13.    static var __hSpacing = 5;
  14.    var __nextDepth = 1;
  15.    function TextPage()
  16.    {
  17.       super();
  18.       mx.events.EventDispatcher.initialize(this);
  19.    }
  20.    function set enabled(activeStatus)
  21.    {
  22.       if(activeStatus == true)
  23.       {
  24.          var _loc2_ = new TextFormat();
  25.          _loc2_.color = 0;
  26.          var _loc3_ = "<headline>" + this.__title.htmlText.slice(18,this.__title.htmlText.length - 19) + "</headline>";
  27.          this.__title.setTextFormat(_loc2_);
  28.          this.__title.setNewTextFormat(_loc2_);
  29.          this.__title.htmlText = _loc3_;
  30.       }
  31.       else
  32.       {
  33.          _loc2_ = new TextFormat();
  34.          _loc2_.color = 8421504;
  35.          _loc3_ = "<headlinedisabled>" + this.__title.htmlText.slice(10,this.__title.htmlText.length - 11) + "</headlinedisabled>";
  36.          this.__title.setTextFormat(_loc2_);
  37.          this.__title.setNewTextFormat(_loc2_);
  38.          this.__title.htmlText = _loc3_;
  39.       }
  40.       this.__body.enabled = activeStatus;
  41.       this.__body.label.selectable = false;
  42.    }
  43.    function init(Void)
  44.    {
  45.       super.init();
  46.    }
  47.    function size(Void)
  48.    {
  49.       super.size();
  50.    }
  51.    function doneSetting()
  52.    {
  53.       this.sendMessage("pageReady");
  54.    }
  55.    function set title(newTitle)
  56.    {
  57.       function workingLayout(bodyText, width, targetObject)
  58.       {
  59.          trace("targetObject: " + targetObject);
  60.          var titleFormat = _level0.styleSheetToTextFormat(_global.textStyles.getStyle("headline"));
  61.          targetObject.html = true;
  62.          with(targetObject)
  63.          {
  64.             embedFonts = true;
  65.             setTextFormat(titleFormat);
  66.             setNewTextFormat(titleFormat);
  67.             styleSheet = _global.textStyles;
  68.             border = false;
  69.             selectable = false;
  70.             autoSize = true;
  71.             borderColor = 13421772;
  72.             multiline = true;
  73.             wordWrap = true;
  74.          }
  75.          var oneRowMetrics = titleFormat.getTextExtent("a",width);
  76.          var twoRowMetrics = titleFormat.getTextExtent("a\na",width);
  77.          var tfhIncrement = twoRowMetrics.textFieldHeight - oneRowMetrics.textFieldHeight;
  78.          var metrics = titleFormat.getTextExtent(bodyText,width);
  79.          var finalHtmlText = "<headline><textformat leading=\'" + myLeading + "\'>" + bodyText + "</textformat></headline>";
  80.          targetObject.htmlText = finalHtmlText;
  81.          var positiveLeading = myLeading >= 0 ? myLeading : - myLeading;
  82.          var calculatedHeight = targetObject._height;
  83.          targetObject.autoSize = false;
  84.          targetObject._height = metrics.textFieldHeight + 1;
  85.          targetObject.htmlText = "<headline><textformat leading=\'0\'>" + bodyText + "</textformat></headline>";
  86.          var unleadedTextHeight1 = targetObject.textHeight;
  87.          var unleadedFieldHeight = targetObject._height;
  88.          targetObject.htmlText = "<headline><textformat leading=\'-1\'>" + bodyText + "</textformat></headline>";
  89.          var unleadedTextHeight2 = targetObject.textHeight;
  90.          var numRows = unleadedTextHeight2 - unleadedTextHeight1;
  91.          numRows = numRows >= 0 ? numRows : - numRows;
  92.          trace("numRows of text: " + numRows);
  93.          targetObject.htmlText = finalHtmlText;
  94.          trace("FINAL TEXTPAGE TITLE: " + finalHtmlText);
  95.          targetObject._height = 38;
  96.       }
  97.       this.createTextField("__title",this.__nextDepth,TextPage.__pageBorder,TextPage.__pageBorder,540,50);
  98.       this.__nextDepth = this.__nextDepth + 1;
  99.       var myLeading = -5;
  100.       var titleFormat = _level0.styleSheetToTextFormat(_global.textStyles.getStyle("headline"));
  101.       workingLayout(newTitle,365,this.__title);
  102.    }
  103.    function set body(bodyText)
  104.    {
  105.       trace("----- TextPage.body -----");
  106.       if(this.__body == undefined)
  107.       {
  108.          this.__body = this.createClassObject(mx.controls.TextArea,"primaryDesc",this.__nextDepth);
  109.          this.__body.editable = false;
  110.          this.__body.label.selectable = false;
  111.          this.__body.wordWrap = true;
  112.          this.__body.borderStyle = "none";
  113.          this.__body.html = true;
  114.          this.__body.embedFonts = true;
  115.          this.__body.styleSheet = _global.textStyles;
  116.          this.__body.setStyle("styleName","scrollTextAreaStyle");
  117.          this.__body.vSB.setStyle("themeColor","0x990000");
  118.          this.__nextDepth = this.__nextDepth + 1;
  119.       }
  120.       if(this.__body.text != bodyText)
  121.       {
  122.          this.__body.text = "<pagebody>" + bodyText + "</pagebody>";
  123.          this.__body._x = TextPage.__pageBorder;
  124.          this.__body._y = this.__title._y + this.__title._height + 2 * TextPage.__vSpacing - 12;
  125.          this.__body.setSize(550,TextPage.__maxPageHeight);
  126.       }
  127.       trace("----- end of TextPage.body -----");
  128.    }
  129.    function removeHTMLTags(htmlText)
  130.    {
  131.       var _loc6_ = function(txt, index)
  132.       {
  133.          return txt.indexOf("<",index);
  134.       };
  135.       var _loc8_ = function(txt, index)
  136.       {
  137.          return txt.indexOf(">",index);
  138.       };
  139.       var _loc2_ = new Array();
  140.       var _loc7_ = 0;
  141.       var _loc9_ = undefined;
  142.       var _loc10_ = undefined;
  143.       while(_loc7_ < htmlText.length)
  144.       {
  145.          _loc9_ = _loc6_(htmlText,_loc7_);
  146.          if(_loc9_ == -1)
  147.          {
  148.             break;
  149.          }
  150.          _loc10_ = _loc8_(htmlText,_loc9_);
  151.          var _loc3_ = _loc6_(htmlText,_loc10_);
  152.          while(_loc3_ == _loc10_ + 1)
  153.          {
  154.             _loc10_ = _loc8_(htmlText,_loc3_);
  155.             _loc3_ = _loc6_(htmlText,_loc10_);
  156.          }
  157.          _loc2_.push({start:_loc9_,end:_loc10_});
  158.          _loc7_ = _loc10_ + 1;
  159.       }
  160.       var _loc5_ = 0;
  161.       while(_loc5_ < _loc2_.length)
  162.       {
  163.          _loc9_ = _loc2_[_loc5_].start;
  164.          var _loc11_ = htmlText.charAt(_loc2_[_loc5_].start);
  165.          _loc10_ = _loc2_[_loc5_].end;
  166.          var _loc12_ = htmlText.charAt(_loc2_[_loc5_].end);
  167.          var _loc16_ = htmlText.substring(_loc9_ + 1,_loc10_);
  168.          _loc5_ = _loc5_ + 1;
  169.       }
  170.       if(_loc2_.length != 0)
  171.       {
  172.          var _loc18_ = "";
  173.          if(_loc2_[0].start > 0)
  174.          {
  175.             _loc18_ += htmlText.substring(0,_loc2_[0].start);
  176.          }
  177.          var _loc4_ = 0;
  178.          while(_loc4_ < _loc2_.length - 1)
  179.          {
  180.             var _loc13_ = _loc2_[_loc4_].end + 1;
  181.             var _loc15_ = _loc2_[_loc4_ + 1].start;
  182.             _loc18_ += htmlText.substring(_loc2_[_loc4_].end + 1,_loc2_[_loc4_ + 1].start);
  183.             _loc4_ = _loc4_ + 1;
  184.          }
  185.          if(_loc2_[_loc2_.length - 1].end < htmlText.length - 1)
  186.          {
  187.             _loc18_ += htmlText.substring(_loc2_[_loc2_.length - 1].end + 1);
  188.          }
  189.          return _loc18_;
  190.       }
  191.       return htmlText;
  192.    }
  193.    function sendMessage(p_msgtxt)
  194.    {
  195.       var _loc2_ = {target:this,type:"pageReady"};
  196.       _loc2_.msgtxt = p_msgtxt;
  197.       _loc2_.pageType = "TextPage";
  198.       this.dispatchEvent(_loc2_);
  199.    }
  200. }
  201.